﻿using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Microsoft.CSharp;

namespace NutriStat
{
    /// <summary>
    /// Base form for the NutriStat project from which all forms and dialogs inherit.
    /// </summary>
    public partial class FormBase : Form
    {
        #region Data
        #region Protected Data
        #endregion Protected Data

        #region Private Data
        private NutriConfig config;
        #endregion Private Data

        #region Internal Data
        #endregion Internal Data
        #endregion Data

        #region Constructors
        /// <summary>
        /// Default constructor
        /// </summary>
        public FormBase()
        {
            InitializeComponent();

            Application.Idle += new System.EventHandler(FormBase_OnIdle);
        }
        #endregion Constructors

        #region Events
        protected void FormBase_Load(object sender, EventArgs e)
        {
            UpdateStatusBar();
        }

        protected void FormBase_OnIdle(object sender, EventArgs e)
        {
            UpdateStatusBarKeys();
        }

        #endregion Events

        #region Properties
        #region Public Properties
        #endregion Public Properties

        #region Protected Properties
        #endregion Protected Properties

        #region Private Properties
        #endregion Private Properties
        #endregion Properties

        #region Methods
        #region Public Methods
        /// <summary>
        /// Tells the main menu to load a specific program configuration.
        /// </summary>
        /// <param name="configuration">The configuration to be loaded.</param>        
        /// <returns>bool</returns>
        internal virtual bool LoadConfigFile(NutriConfig configuration)
        {
            try
            {
                this.config = new NutriConfig(configuration);
            }
            catch (Exception ex)
            {
                MessageBox.Show(SharedStrings.ERROR_CONFIG_FILE_LOAD1 + ex.ToString());
                return false;
            }
            finally
            {
                ConfigureFormControls();
                RefreshData(0);
            }
            return true;
        }

        /// <summary>
        /// Refreshes all of the form's form controls
        /// </summary>
        /// <param name="stats">The type of refresh to be conducted</param>
        internal virtual void RefreshData(int type)
        {
            #region Input Validation
            // Input validation
            if (type < 0 || type > 8)
                throw new Exception(SharedStrings.ERROR_PARAMETER1 + type.ToString());
            #endregion
        }
        #endregion Public Methods

        #region Protected Methods
        /// <summary>
        /// Configures the form controls based on the user's preferences, as defined in the options. This
        /// includes loading language-specific strings.
        /// </summary>
        protected internal virtual NutriPatient GuiMediator()
        {
            NutriPatient patient = new NutriPatient();
            return patient;
        }

        /// <summary>
        /// Configures the form controls based on the user's preferences, as defined in the options. This
        /// includes loading language-specific strings.
        /// </summary>
        protected internal virtual void ConfigureFormControls()
        {
        }

        /// <summary>
        /// Populates the form's controls with data.
        /// </summary>
        protected internal virtual void PopulateFormControls()
        {
        }

        /// <summary>
        /// Updates the form's status bar.
        /// </summary>
        protected virtual void UpdateStatusBar()
        {
            UpdateStatusBarKeys();
        }

        /// <summary>
        /// Updates the state of the INS, Caps lock and Num lock keys on the status bar.
        /// </summary>
        protected virtual void UpdateStatusBarKeys()
        {            
        }

        /// <summary>
        /// Opens a database for use in the form
        /// </summary>
        protected internal virtual void OpenDatabase()
        {            
        }
        #endregion Protected Methods  

        #region Private Methods        
        #endregion Private Methods
        #endregion Methods
    } // end class
}
